package com.csi.jf.crucible.ptservice.service.impl;


import com.chinasofti.ro.bizframework.core.orm.IDAO;
import com.chinasofti.ro.bizframework.core.orm.Page;
import com.chinasofti.ro.bizframework.core.orm.entity.Model;
import com.csi.jf.crucible.ptservice.model.PrjAssociate;
import com.csi.jf.crucible.ptservice.service.PrjAssociateService;

/**
 * @Title: PrjAssociateServiceImpl.java
 * @Description: <br>
 *               <br>
 * @Company: ICSS
 * @Created on 2014-7-7 下午10:32:12
 * @author FengHaiBing
 */
public class PrjAssociateServiceImpl implements PrjAssociateService {

	private IDAO dao;
	
	public void setDao(IDAO dao) {
		this.dao = dao;
	}

	/**
	 * 根据id查询数据
	 * 
	 * @param id
	 * @return Model
	 */
	public Model findById(Long id) {
		PrjAssociate projectCru = new PrjAssociate();
		projectCru.setId(id);
		return (Model) dao.createQuery(projectCru).first();
	}
	
	@Override
	public Model findByJfId(Long jfId) {
		PrjAssociate projectCru = new PrjAssociate();
		projectCru.setPrjJfId(jfId);
		return (Model) dao.createQuery(projectCru).first();
	}
	
	/**
	 * 分页查询
	 * 
	 * @param prjAssociate
	 * @param page 分页
	 * @return
	 */
	public Page findByPage(PrjAssociate prjAssociate, Page page) {
		String sql = prjAssociate.getSql("list", dao.dbMeta());//使用projectCru.hbm.xml中的id为list的sql查询
		return dao.createNamedQuery(prjAssociate.getClass(),sql, prjAssociate).fetch(page);
	}
	
	/**
	 * 批量删除数据
	 * 
	 * @param ids
	 * @return int[] delete records
	 */
	public int[] batchDelete(String ids) {
		PrjAssociate projectCru = new PrjAssociate();
		return dao.batchDelete(projectCru, ids);
	}

	/**
	 * 保存数据
	 * @param Model
	 */
	public void save(Model model) {
		dao.save(model);
		
//		//create project on crucible
//		ProjectCru pc = (ProjectCru)model;
//		ApiTestProject test = new ApiTestProject();
//		test.createProject(pc.getPrjCruName(), pc.getPrjCruKey());
	}

	/**
	 * 更新数据
	 * @param Model
	 */
	public void update(Model model) {
		dao.update(model);
	}

}